package com.yootkdemo;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class YootkDemo1 {
    public static AtomicInteger money = new AtomicInteger();

    public static void main(String[] args) throws Exception {
        int[] data = new int[]{100, 200, 300};
//待存款金额
        for (int x = 0; x < data.length; x++) { //循环创建子线程
            final int temp = x;

            new Thread(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(100); //模拟存款延迟
                } catch (InterruptedException e){}
                money.addAndGet(data[temp]);
//金额累加
            }).start();
//线程启动
        }
        TimeUnit.SECONDS.sleep(1);
//等待子线程处理完成
        System.out.println("【计算完成】最终存款总额:" + money);
    }
}